import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { CookieService } from 'angular2-cookie/services/cookies.service';

import { Config } from '../share/config';

@Injectable()
export class SysinfoService {

  constructor(
    private http: Http,
    private _cookieService: CookieService
  ) { }

  /* 获取系统信息 */
  getSysinfo(): Observable<any> {
    const url = `${Config.apiRoot}sysinfo`;
    return this.http.get(url)
      .map(this.extraData)
      .catch(this.handleError);
  }

  private extraData(res) {
    const body = res.json();
    return body || [];
  }

  private handleError(error) {
    const errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : `Server error`;
    console.error(errMsg);

    return Observable.throw(errMsg);
  }
}
